using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace XnaDevRu.BulletX
{
	public class LocalSupportVertexCallback : ITriangleIndexCallback
	{
		private Vector3 _supportVertexLocal;
		private float _maxDot;
		private Vector3 _supportVecLocal;

		public LocalSupportVertexCallback(Vector3 supportVecLocal)
		{
			_supportVertexLocal = new Vector3();
			_maxDot = -1e30f;
			_supportVecLocal = supportVecLocal;
		}

		public float MaxDot { get { return _maxDot; } set { _maxDot = value; } }
		public Vector3 SupportVertexLocal { get { return _supportVecLocal; } set { _supportVecLocal = value; } }

		public void ProcessTriangleIndex(Vector3[] triangle, int partId, int triangleIndex)
		{
			for (int i = 0; i < 3; i++)
			{
				float dot = Vector3.Dot(_supportVecLocal, triangle[i]);
				if (dot > _maxDot)
				{
					_maxDot = dot;
					_supportVertexLocal = triangle[i];
				}
			}
		}
	}
}
